Day 1: Variables and Data Types
Variable Declaration
Python allows you to create variables without declaring a type.
name = "John"
age = 25
height = 175.5
is_student = True
Basic Data Types
| Type | Example | Description |
|---|---|---|
int | 42 | Integer |
float | 3.14 | Floating-point number |
str | "hello" | String |
bool | True | Boolean |
None | None | No value |
Checking Types
x = 42
print(type(x)) # <class 'int'>
y = "hello"
print(type(y)) # <class 'str'>
Type Conversion
# String -> Integer
num = int("123")
# Integer -> String
text = str(456)
# Float -> Integer (decimal part is truncated)
n = int(3.7) # 3
Today’s Exercises
- Store your name, age, and height in variables and print them.
- Use the
type()function to check the type of each variable. - Convert the string
"100"to an integer and add 50 to it.